import { useDispatch, useSelector } from 'react-redux'
import { addAction } from './store/actions/count'

export default function App() {
  // 获取仓库的 count 数据
  const count = useSelector((state) => state.count)
  const dispatch = useDispatch()
  return (
    <div>
      <h1>App根组件</h1>
      <h2>仓库数据:{count}</h2>
      <button onClick={() => dispatch(addAction(1))}>点击+1</button>
      <h3>-------------------------------------</h3>
      <Son />
    </div>
  )
}

// 子组件
function Son() {
  const count = useSelector((state) => state.count)
  const dispatch = useDispatch()
  return (
    <div>
      <h3>子组件获取仓库数据:{count}</h3>
      <button onClick={() => dispatch(addAction(10))}>点击+10</button>
    </div>
  )
}
